{extend name='template/base'}{/extend}
{block name='style'}{/block}
{block name='script'}{/block}
{block name='content'}
<div class="wrapper">
    <div class="row">
        <div class="col-xs-12">
            <div class="box">
                <div class="box-body">
                    <div id="toolbar">
                        <div class="btn-group pull-left mr10">
                            <a class="btn btn-primary" id="add_btn"><i class="fa fa-plus"></i> 新增角色</a>
                        </div>
                    </div>
                    <table id="table"
                           data-toggle="table"
                           data-show-refresh="true"
                           data-side-pagination="server"
                           data-pagination="true"
                           data-url="{:url('AdminRole/index_data')}"
                    >
                        <thead>
                        <tr>
                            <th data-field="name">角色名称</th>
                            <th data-field="name">状态</th>
                            <th data-field="operate" data-formatter="formatOperate" data-events="operateEvents">操作</th>
                        </tr>
                        </thead>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>
{/block}
{block name='script_extra'}
<script>
    var add_data_url = "{:url('AdminRole/add')}";
    var edit_data_url = "{:url('AdminRole/edit')}";
    var delete_data_url = "{:url('AdminRole/delete')}";
    var power_data_url="{:url('AdminRole/power')}";
</script>
<script>
    function urlFormat(url) {
        if (url.indexOf(".html")) {
            url = url.replace('.html', '');
        }
        return url;
    }
    // <editor-fold defaultstate="collapsed" desc="增加">
    $('#add_btn').on('click', function () {
        layer_open('添加角色', add_data_url)
    });
    // </editor-fold>
    // <editor-fold defaultstate="collapsed" desc="操作按钮">
    function formatOperate(value,row,index) {
        return [
            '<button class="btn btn-success btn-xs row_power" href="javascript:void(0)">',
            '<i class="fa  fa-expeditedssl"></i> 权限分配',
            '</button>&nbsp;',
            '<button class="btn btn-warning btn-xs row_edit" href="javascript:void(0)">',
            '<i class="fa fa-edit"></i> 修改',
            '</button>&nbsp;',
            '<button class="btn btn-danger btn-xs row_delete" href="javascript:void(0)">',
            '<i class="fa fa-trash"></i> 删除',
            '</button>'
        ].join('');

    }
    // </editor-fold>
    // <editor-fold defaultstate="collapsed" desc="操作函数">
    window.operateEvents = {
        'click .row_power': function (e, value, row, index) {
            layer_open('权限分配',urlFormat(power_data_url)+"/id/"+row.id);
        },
        'click .row_edit': function (e, value, row, index) {
            layer_open('编辑',urlFormat(edit_data_url)+"/id/"+row.id);
        },
        'click .row_delete': function (e, value, row, index) {
            layer.confirm('你确定要删除该选项吗？',{btn:['确定','取消']},function () {
                $.ajax({
                    dataType:'json',
                    data:{id:row.id},
                    url:delete_data_url,
                    success:function (res) {
                        if(res.success){
                            layer.msg(res.message, {time: 1000},function () {
                                $('#table').bootstrapTable('refresh');
                            });
                        }else{
                            layer.alert(res.message);
                        }
                    }
                })
            })
        },
    }
    // </editor-fold>
</script>

{/block}